package commandPatern;

import gui.abstracts.AbstractTable;
import gui.panels.PanelGroup;

import java.sql.SQLException;

import bean.UniversityBean;

import dao.UniversityDAO;

public class Update implements Command {

	private UniversityBean universityOld;
	private UniversityBean universityNew;
	private int nrRow;
	private AbstractTable abstractTable;
	
	public Update (UniversityBean universityOld, int nrRow, AbstractTable abstractTable){
		this.universityOld = universityOld;
		this.nrRow = nrRow;
		this.abstractTable = abstractTable;
		System.out.println(universityOld.getRow());
	}
	
	public UniversityBean getUniversityNew() {
		return universityNew;
	}
	
	public UniversityBean getUniversityold() {
		return universityOld;
	}

	public void setUniversityNew(UniversityBean universityNew) {
		this.universityNew = universityNew;
		System.out.println(universityNew.getRow());
	}


	
	@Override
	public void undo() throws InstantiationException, IllegalAccessException,
			ClassNotFoundException, SQLException {
	
		UniversityDAO uDaoNew = universityNew.getDAO();
		uDaoNew.Delet(universityNew);
		
		abstractTable.getDefaultTableMOdel().removeRow(nrRow);
		
		abstractTable.getDefaultTableMOdel().insertRow(nrRow, universityOld.getRow());
		
		UniversityDAO uDaoOld = universityOld.getDAO();
		uDaoOld.Insert(universityOld);

	}

	@Override
	public void rendoo() throws InstantiationException, IllegalAccessException,ClassNotFoundException, SQLException {

		abstractTable.getDefaultTableMOdel().removeRow(nrRow);
		
		abstractTable.getDefaultTableMOdel().insertRow(nrRow, universityNew.getRow());
		System.out.println("rendoo "+universityOld.getRow());
		UniversityDAO uDaoOld = universityOld.getDAO();
		uDaoOld.Delet(universityOld);
		
		UniversityDAO uDaoNew = universityNew.getDAO();
		uDaoNew.Insert(universityNew);
		
		


		
	}

}
